﻿#ifndef MYTABLEITEMDELEGATE_H
#define MYTABLEITEMDELEGATE_H

#pragma once

#include <QStyleOptionViewItem>
#include <QWidget>
#include <QItemDelegate>
#include <QModelIndex>
#include <QAbstractItemModel>
#include "mytabledata.h"
#include "DbCfgFun.h"

class MenuInfo;

class MyTableItemDelegate : public QItemDelegate
{
	Q_OBJECT
public:
    MyTableItemDelegate(MyTableData *pTableData,/*int TableType,*/ QWidget *parent = 0);
	~MyTableItemDelegate();
// 
public:
	// 当双击表格里的某一个元素时，会调用这个函数，创造一个Editor
	QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;

	// 用于把模型的数据传递给代理类的控件
	void setEditorData(QWidget *editor, const QModelIndex &index) const;
	// 用于提交修改的数据
	void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;

	void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;

protected:
	//设置相关记录同一字段内容
	void SetSibRecordColumn(QAbstractItemModel *model, const QModelIndex &OldIndex, int SibRowNo, int FieldNo, QString ItemText, QVariant ItemData) const;
	//设置记录相关字段内容
	void SetRelateColumnData(QAbstractItemModel *model, const QModelIndex &OldIndex, int RowNo, int RelateFieldNo, QString ItemText, QVariant ItemData) const;
signals:
	void UserDataChang(int RecordNo, int ColumnNo) const;
	void RefreshShow(int RecId1, int RecId2,int RecId3, int FieldNo) const;

private:
	MyTableData		*m_pTableData;
	MenuInfo		*m_pMenuInfo;
	//int				m_TableType;

private:

};

#endif // MYTABLEITEMDELEGATE_H
